package com.jrx.anytxn.transaction.job.customer.config;

import com.jrx.anytxn.common.constant.Constants;
import com.jrx.anytxn.customer.service.ICustomerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 补充二类户开户时联网核查
 * @author liuzb
 */
@Configuration
public class InternetCheckAgainConfiguration {

    private static final Logger logger =  LoggerFactory.getLogger(InternetCheckAgainConfiguration.class);

    @Autowired
    public JobBuilderFactory jobBuilderFactory;
    @Autowired
    public StepBuilderFactory stepBuilderFactory;
    @Autowired
    public ICustomerService iCustomerService;

    @Bean
    public Job internetCheckAgainJob() {
        return jobBuilderFactory.get("internetCheckAgainJob")
                .start(internetCheckAgainStep()).build();
    }

    @Bean
    public Step internetCheckAgainStep() {
        return stepBuilderFactory.get("internetCheckAgainStep")
                .tasklet(internetCheckAgainTasklet()).build();
    }

    @Bean
    @StepScope
    public Tasklet internetCheckAgainTasklet() {
        return (stepContribution, chunkContext) -> {
            logger.info("access into internetCheckAgainSTasklet");
            iCustomerService.internetCheckAgain();
            return RepeatStatus.FINISHED;
        };
    }
}
